package com.back.supplier.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.back.supplier.bean.Tbl_supplier;
import com.back.supplier.service.SupplierService;

@Controller
public class SupplierAction {
	
	@Autowired
	private SupplierService service;
	
	@RequestMapping("/addSupplier")
	public String addSupplier(Tbl_supplier supplier){
		System.out.println(supplier);
		
		service.addSupplier(supplier);
		
		return "redirect:/findSuppliers.action";
	}
	@RequestMapping("/findSuppliers")
	public String findSuppliers(Tbl_supplier supplier,HttpServletRequest request){
		System.out.println(supplier);
		List<Tbl_supplier> list = service.findSupplier(supplier);
		System.out.println(list);
		request.getSession().setAttribute("list", list);
		return "redirect:/jsps/supplier/list.jsp";
	}
	@RequestMapping("/delSupplier")
	public String del(Integer uuid){
		int a = service.delSupplier(uuid);
		System.out.println(a);
		return "redirect:/findSuppliers.action";
	}
	@RequestMapping("/findById")
	public String findById(Integer uuid,HttpServletRequest request){
		System.out.println(uuid);
		Tbl_supplier supplier = service.findById(uuid);
		System.out.println("..."+supplier);
		request.getSession().setAttribute("supplier", supplier);
		return "redirect:/jsps/supplier/gai.jsp";
	}
	@RequestMapping("/update")
	public String update(Tbl_supplier supplier){
		service.update(supplier);
		return "redirect:/findSuppliers.action";
	}
	
}
